<?php
class voice extends CI_Controller {
	function index() {
		$this -> pub -> logp('课程管理', '2', 'plug_voice');
		$da = $this -> pub -> get_setting('课程', 'Course');
		$this -> load -> view('adminx/voice', $da);
	}

	function add() {
		$this -> pub -> logp('创建课程', '1-2');
		$da['daoshi_id'] = $this -> input -> post('daoshi_id');
		$da['sp_id'] = $this -> input -> post('sp_id');
		$da['url'] = $this -> input -> post('url');
		$da['yg'] = $this -> input -> post('yg');
		$this -> db -> insert('sp_voice', $da);
		echo json_encode(array('type' => 1));
	}

	function up() {
		$this -> pub -> logp('课程修改 - ' . $this -> input -> post('idx'), '1-2');
		$da['daoshi_id'] = $this -> input -> post('daoshi_id');
		$da['sp_id'] = $this -> input -> post('sp_id');
		$da['url'] = $this -> input -> post('url');
		$da['yg'] = $this -> input -> post('yg');
		$this -> db -> update('sp_voice', $da, array('sp_id' => $this -> input -> post('idx')));
		echo json_encode(array('type' => 1));
	}

	function get_one() {
		$this -> pub -> logp('获取课程信息 - ' . $this -> input -> post('idx'), '1-2');
		$q = $this -> db -> get_where('sp_voice', array('sp_id' => $this -> input -> post('idx')));
		if ($q -> num_rows() > 0) {
			$da = $q -> row_array(0);
			$da['typex'] = 1;
			echo json_encode($da);
		} else {
			echo json_encode(array('typex' => 2));
		}
	}

	function get() {
		$this -> pub -> logp('获取课程信息', '1-2');
		if ($this -> input -> post('key')) {
			$this -> db -> where('sp_id', $this -> input -> post('key'));
		}
		$q = $this -> db -> get_where('sp_voice');
		$da['content'] = '';
		foreach ($q->result_array() as $v) {
			$qq = $this -> db -> get_where('sp', array('sp_id' => $v['sp_id']));
			$ls = $qq -> row_array(0);

			$qq = $this -> db -> get_where('sp_daoshi', array('id' => $v['daoshi_id']));
			$daoshi = $qq -> row_array(0);
			$da['content'] .= '<tr>';
			$da['content'] .= '<td>' . $v['sp_id'] . '</td>';
			$da['content'] .= '<td><img width="80" src="' . $this -> pub -> oss_dz($ls['pic1']) . '" /></td>';
			$da['content'] .= '<td>' . $daoshi['name'] . '</td>';
			$da['content'] .= '<td>' . $ls['name'] . '</td>';
			$da['content'] .= '<td>' . $ls['price'] . '</td>';
			$da['content'] .= '<td><button onclick="show_up(\'' . $v['sp_id'] . '\')" type="button"  class="btn default"><i class="fa fa-edit"></i>修改</button>  </td>';
			$da['content'] .= '</tr>';
		}
		$da['type'] = 1;
		echo json_encode($da);
	}

}
?>